package edu.iwyf.pms.util;

import org.springframework.util.DigestUtils;

import java.util.Random;

/**
 * @Author 王永飞
 * 2021/12/21 15:18
 */
public class PassWordUtil {
    //产生盐
    public static final String creatSalt(){
        Random ran = new Random();
        String base="0123456789abcdefgigjjkkhhsdsdjladABCDEFHJWA0QSACKXZL,/()=@#!#$%%";
        StringBuffer str = new StringBuffer(16);
        for (int i=0;i<16;i++){
            str.append(base.charAt(ran.nextInt(base.length())));
        }
        return str.toString();
    }

    //进行加密
    public static final String encryption(String pass,String salt,int count){
        for (int i =0;i<count;i++){
            pass+=salt;
        }
        //进行md5加密
        pass = DigestUtils.md5DigestAsHex(pass.getBytes());
        return pass;
    }

//    public static void main(String[] args) {
//        String str1="aaa";
//        String salt=PassWordUtil.creatSalt();
//        String str2=PassWordUtil.encryption(str1,salt,2);
//        System.out.println(str2);
//        System.out.println(str1);
//        System.out.println(salt);
//    }
}


